<%@ page language="java" import="java.util.*,com.hs.wdss.model.*,com.hs.core.cache.*" pageEncoding="utf-8"%>
<%
	WdssDisinfo obj = (WdssDisinfo)request.getAttribute("obj");
	List cureselect = (List)request.getAttribute("cureselect");
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="../../include.jsp"%>  
<script src="<%=basePath %>app/javascripts/transform.js"></script>
<script src='<%=basePath%>dwr/interface/dataProhelper.js'></script>  
<script language="javascript" type="text/javascript">
//治法相关方法
function delCure(id){
	if(confirm("确认要删除该治法吗？")){
    		dataProhelper.queryPrecout(id,callback4delCurecheck);
    }
}
function callback4delCurecheck(data){
	if("" == data){
		alert("请先删除该治法相关的方剂");
		return; 
	}else{
		dataProhelper.delCure(data,callback4delCure);
	} 
}
function callback4delCure(data){   
	document.getElementById("cure_"+data).style.display="none"; 
	//刷新左边菜单
	var wdssid = window.parent.datapromenu.document.all.wdssid.value;
	window.parent.datapromenu.frameElement.src = "<%=basePath%>produce/datapromenu.do?wdssid="+wdssid;
}
//方剂相关方法
function savepredata()
{
	var wdssid = window.parent.datapromenu.document.all.wdssid.value;
	if(wdssid == ""){
		alert("请先保存医案信息！");	
		return;
	}else {
		var prename = document.getElementById("prename").value; 
		var memo = document.getElementById("memo").value; 
		var cureidvalue = "";
		var cureid = getRadioValue("cure");
		if("undefined" != typeof(cureid)){
			cureidvalue = cureid;
		} 
		if(isNull(prename)){
			alert("请输入方剂名称！");
			return; 
   		}
	   	dataProhelper.addPre(prename,memo,wdssid,cureidvalue,callback4addPre);
	}
	
}
function callback4addPre(data){ 
	   var index = data.indexOf("$");
       var preid = data.substring(0,index);
       var prename = data.substring(index+1);  
       var str = "<span id=pre_"+preid+"><input type=radio onclick=viewHerb('"+preid+"') value="+preid+" name=pre><font size='5'>" + prename+"</font>&nbsp;&nbsp;<a href='javaScript:delPre("+preid+");'>删除</a>&nbsp;&nbsp;</span>";
       var objHtml = document.getElementById("preinfo");
       var temp = objHtml.innerHTML + str;
       objHtml.innerHTML = temp; 
       alert('方剂信息保存成功！');   
       document.getElementById("prename").value='';
       document.getElementById("memo").value='';
       document.getElementById("prename").focus(); 
       //刷新左边菜单
	 	var wdssid = window.parent.datapromenu.document.all.wdssid.value;
	 	window.parent.datapromenu.frameElement.src = "<%=basePath%>produce/datapromenu.do?wdssid="+wdssid;
}
function delPre(id){
	if(confirm("确认要删除该方剂吗？")){
    		dataProhelper.queryHerbcout(id,callback4delPrecheck);
    }
}
function callback4delPrecheck(data){
	if("" == data){
		alert("请先删除该方剂相关的中药信息");
		return; 
	}else{
		dataProhelper.delPre(data,callback4delPre);
	} 
}
function callback4delPre(data){   
	document.getElementById("pre_"+data).style.display="none"; 
	//刷新左边菜单
	 var wdssid = window.parent.datapromenu.document.all.wdssid.value;
	 window.parent.datapromenu.frameElement.src = "<%=basePath%>produce/datapromenu.do?wdssid="+wdssid;
}
function viewHerb(){
}
function viewPre(){
}
//中药相关方法
function saveherbdata(){
	var wdssid = window.parent.datapromenu.document.all.wdssid.value;
	if(wdssid == ""){
		alert("请先保存医案信息！");	
		return;
	}else {
		var herbname = document.getElementById("herbname").value; 
	 	var jiliang = document.getElementById("jiliang").value; 
	 	var unittype = document.getElementById("unittype").value; 
	 	var funcinfo = document.getElementById("funcinfo").value; 
	 	var method = document.getElementById("method").value; 
	 	var memo = document.getElementById("memo").value; 
	 	var preidvalue = "";
	 	var preid = getRadioValue("pre");  
	 	if("undefined" != typeof(preid)){
			preidvalue = preid;
		}  
		if(isNull(preidvalue)){
			alert("请选择该中药所属方剂！");
			return;
		}
		if(isNull(herbname)){
			alert("请输入中药名称！");
			return; 
	    }
	    dataProhelper.addHerb(herbname,jiliang,unittype,method,funcinfo,memo,preidvalue,wdssid,callback4addHerb);
	
	}
 	
}
var herbid = "";
function callback4addHerb(message){  
	   var cellFunctions = [    
          function(item) {   
           	return item.herbname;
          },   
          function(item) {  
           	return item.jiliang;
          },
          function(item) {  
           	return item.unittype;
          },
          function(item) {  
           	return item.method;
          },
          function(item) {  
           	return item.funcinfo;
          },
          function(item) {  
           	return item.memo;
          },
          function(item) {  
           	return "<a href=javaScript:onclick=delHerb('"+item.id+"');>删 除</a>";
          }
      ];    
     var index = message.indexOf("$");  
     herbid = message.substring(0,index); 
     var rowdata = message.substring(index+1); 
     var data = eval('('+rowdata+')');   
      DWRUtil.addRows("herblist", data, cellFunctions,{
          rowCreator:function(options) { //自定义 tr 的创建行为 
          var trobj = document.createElement("tr");   
          trobj.setAttribute("id","herb_"+herbid);  
          return trobj; 
     },cellCreator:function(options) {
	var cell = document.createElement("td"); 
	return cell;
}, escapeHtml:false
     });
    alert('中药信息保存成功！'); 
    document.getElementById("herbname").value='';  
 	document.getElementById("jiliang").value='';  
 	document.getElementById("unittype").value='';  
 	document.getElementById("method").value='';  
 	document.getElementById("funcinfo").value='';  
 	document.getElementById("herbmemo").value='';  
 	document.getElementById("herbname").focus(); 
 	//刷新左边菜单
	var wdssid = window.parent.datapromenu.document.all.wdssid.value;
	window.parent.datapromenu.frameElement.src = "<%=basePath%>produce/datapromenu.do?wdssid="+wdssid;
}
function delHerb(id){ 
	if(confirm("确认要删除该中药吗？")){
    		dataProhelper.delHerb(id,callback4delHerb);
    }
}
function callback4delHerb(data){   
	var tbody  = document.getElementById("herblist");// tbody 的id 
    var rowobj = document.getElementById("herb_"+data);  
    tbody.removeChild(rowobj);
    //刷新左边菜单
	var wdssid = window.parent.datapromenu.document.all.wdssid.value;
	window.parent.datapromenu.frameElement.src = "<%=basePath%>produce/datapromenu.do?wdssid="+wdssid;
}
function backlist()
{
	window.parent.window.location.href = "<%=basePath%>produce/dataprolist.do"
}
</script>
</head>
<body>
<div class="current">当前位置：数据加工 &gt; 方剂信息</div>
  	<table border="0" cellspacing="0" cellpadding="0"  class="news">
		  <tr>
		 	  <th width="15%">本医案已添加的治法</th>
	          <td width="85%">
	          
	           <%
	           if(cureselect.size()>0){   
	                   for(int i =0;i<cureselect.size();i++){ 
	          	             Map cure = (Map)cureselect.get(i); 
	          	             String cureid = (String)cure.get("ID"); 
	          	             String value = (String)cure.get("VALUE"); 
	          	             
	          	             out.print("<span id=cure_"+cureid+"><input type=radio onclick=viewPre('"+cureid+"') value="+cureid+" name=cure><font size='5'>"+value+"</font>");
	          	             out.print("<a href=javaScript:delCure('"+cureid+"');>");
	          	             out.print(" 删 除 </a></span>"); 
	           		}
	           	}
              %> 
	          </td>
          </tr>
        </table>
        <table border="0" cellspacing="0" cellpadding="0" class="news"> 
        <caption>
          方剂信息
          </caption>
          <tr>
            <th width="15%">方剂名称</th>
            <td width="35%"><input type="text" name="prename" id="prename" value="" style="width:98%"/>
            <input name="disid" type="hidden" value=""/>
            <input name="discauseid" type="hidden" value=""/></td> 
            <th width="15%">备注</th>
            <td><input type="text" name="memo" id="memo" value="" style="width:98%"/>
            </td> 
          </tr>
          <tr> 
           <td colspan=4 align=center>
           		<input  type="button" value=" 保 存 " onclick="savepredata();" class="butt"/>
           		<input  type="button" value=" 返 回 " onclick="backlist();" class="butt"/>
           </td>
          </tr>
        </table> 
       <table border="0" cellspacing="0" cellpadding="0"  class="news">
		  <tr>
		 	  <th width="15%">本医案已选方剂：</th>
	          <td width="85%" id="preinfo">
	           <%
	            if(null != obj && !(obj.getPreset().isEmpty())){  
	                   Iterator preiter = obj.getPreset().iterator(); 
	                   while(preiter.hasNext()){ 
	          	             WdssPreinfo pre = (WdssPreinfo)preiter.next(); 
	          	             Long preid = pre.getId(); 
	          	             
	          	             out.print("<span id=pre_"+preid+"><input type=radio onclick=viewHerb('"+preid+"') value="+preid+" name=pre><font size='5'>"+pre.getPrename()+"</font>");
	          	             out.print("<a href=javaScript:delPre('"+preid+"');>");
	          	             out.print(" 删 除 </a></span>"); 
	           		}
	           	}
              %> 
	          </td>
          </tr>
        </table>
         <table border="0" cellspacing="0" cellpadding="0" class="news"> 
        <caption>
          中药信息
          </caption>
          <tr>
            <th width="15%">中药名称</th>
            <td width="35%"><input type="text" name="herbname" id="herbname" value="" style="width:95%"/>
            <input name="disid" type="hidden" value=""/>
            <input name="discauseid" type="hidden" value=""/></td>
            <th width="15%">剂量</th>
            <td width="35%"><input type="text" name="jiliang" id="jiliang" value="" style="width:95%"/>
            </td> 
            </tr>
            <tr>
             <th width="15%">剂量单位</th>
            <td width="35%"><input type="text" name="unittype" id="unittype" value="" style="width:95%"/>
            </td> 
            <th width="15%">用法</th>
            <td width="35%"><input type="text" name="method" id="method" value="" style="width:95%"/>
            </td> 
          </tr>
           <tr> 
            <th width="15%">备注</th>
            <td colspan="4"><input type="hidden" name="funcinfo" id="funcinfo" value="" style="width:98%"/><input type="text" name="herbmemo" id="herbmemo" value="" style="width:97%"/>
            </td> 
          </tr>
          <tr> 
           <td colspan=4  align=center>
           		<input  type="button" value=" 保 存 " onclick="saveherbdata();" class="butt"/>
           		<input  type="button" value=" 返 回 " onclick="backlist();" class="butt"/>
           </td>
          </tr> 
        </table> 
      <table border="0" cellspacing="0" cellpadding="0" style="width:100%" class="list">
          <tr> 
            <th width="20%">中药名称</th>
            <th width="10%">剂量</th>
            <th width="10%">剂量单位</th>
            <th width="10%">用法</th>
            <th width="10%">功效</th>
            <th width="30%">备注</th> 
            <th width="10%">删除</th> 
          </tr>
          <tbody id=herblist>
           <%if(obj != null && !obj.getHerbset().isEmpty()){
                Set herbset = obj.getHerbset();
                Iterator iter = herbset.iterator();
          		while(iter.hasNext()){
          			WdssHerbinfo herbinfo = (WdssHerbinfo)iter.next();
           %>
	           <tr id=herb_<%=herbinfo.getId() %>>
 	           <td style="word-break:break-all;over-flow:hidden;"><%=StringUtilTool.NULL2Blank(herbinfo.getHerbname())%></td>
 	           <td style="word-break:break-all;over-flow:hidden;"><%=StringUtilTool.NULL2Blank(herbinfo.getJiliang())%></td>
 	           <td style="word-break:break-all;over-flow:hidden;"><%=StringUtilTool.NULL2Blank(herbinfo.getUnittype())%></td>
 	           <td style="word-break:break-all;over-flow:hidden;"><%=StringUtilTool.NULL2Blank(herbinfo.getMethod())%></td>
 	           <td style="word-break:break-all;over-flow:hidden;"><%=StringUtilTool.NULL2Blank(herbinfo.getFuncinfo())%></td>
 	           <td style="word-break:break-all;over-flow:hidden;"><%=StringUtilTool.NULL2Blank(herbinfo.getMemo())%></td>
 	           <td><a href="javaScript:onclick=delHerb('<%=herbinfo.getId() %>')">删除</a></td>
	           </tr>
           <%}} %>
           </tbody>
        </table>
</body>
</html>


